import Router from 'vue-router'
import Vue from 'vue'
import frame from './components/appFrame.vue'
import login from './components/login.vue'
import statistic from './components/manage/statistic.vue'
import userManage from './components/manage/userManage.vue'
import activityDetail from './components/manage/detail.vue'
import axios from 'axios'

Vue.use(Router);

const router = new Router({
    routes: [
        {
            path: '/login',
            name: 'login',
            component: login,
            // beforeEnter: (to, from, next) => {
            //     axios.get(apiHost + '/user_info/', {
            //         withCredentials: true,
            //         params: {time: new Date().getTime()}
            //     }).then(res => {
            //         next('/home/statistic/1,2,3')
            //     }).catch(e => {
            //         next()
            //     })
            // },
        },
        {
            path: '/home',
            name: 'frame',
            component: frame,
            // beforeEnter: (to, from, next) => {
            //     axios.get(apiHost + '/user_info/', {
            //         withCredentials: true,
            //         params: {time: new Date().getTime()}
            //     }).then(res => {
            //         next()
            //     }).catch(e => {
            //         next('/login')
            //     })
            // },
            children: [
                {
                    path: 'statistic/:filter',
                    name: 'statistic',
                    component: statistic
                },
                {
                    path: 'activityDetail/:filter/:actID',
                    name: 'activityDetail',
                    component: activityDetail
                },
                {
                    path: 'userManage/:filter',
                    name: 'userManage',
                    component: userManage
                }
            ]
        },
        {
            path: '*',
            redirect: '/home/statistic/1,2,3'
        }
    ],
});

export default router